package com.yxj.securityhello.controller;

import com.mysql.cj.util.StringUtils;
import com.yxj.securityhello.common.R;
import com.yxj.securityhello.domain.Svsuser;
import com.yxj.securityhello.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangxuejiao
 * @description
 * @createDate 2025/11/2 23:02
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public R login(@RequestBody Svsuser user) {
        String jwt = userService.login(user);
        if (StringUtils.isNullOrEmpty(jwt)) {
            return R.error().message("登录失败");
        } else {
            return R.ok().message("登录成功").data("token", jwt);
        }

    }
}
